/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simplemetrosystem.view.menu;

import java.util.Observable;
import java.util.Observer;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import simplemetrosystem.model.charlanguage.NameMap;
import simplemetrosystem.view.MetroFrame;

/**
 *
 * @author Eric Qian
 */
public class ModelMenu extends JMenu implements Observer {

    /**
     * 初始化编辑菜单
     * @param frame
     */
    public ModelMenu(MetroFrame frame) {
        super();
        name = NameMap.getInstance().getName("Model");
        this.setText(name);
        this.frame = frame;

        addItem();
    }

    private void addItem() {
        add(getModelEditItem());
        add(getCalCalItem());
    }

    /**
     * 
     * @return
     */
    public JMenuItem getCalCalItem() {
        if (ccItem == null) {
            ccItem = new ModCalItem(frame);
            Icon icon = new ImageIcon("icon/calmodel.gif");
            ccItem.setIcon(icon);
        }
        return ccItem;
    }

    public JMenuItem getModelEditItem() {
        if (meItem == null) {
            meItem = new ModelEditItem(frame);
            meItem.setEnabled(false);
            Icon icon = new ImageIcon("icon/editmodel.gif");
            meItem.setIcon(icon);
        }
        return meItem;
    }

    public void update(Observable o, Object arg) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void setModel(boolean model) {
        if (model) {
            meItem.setEnabled(true);
            ccItem.setEnabled(false);
        } else {
            meItem.setEnabled(false);
            ccItem.setEnabled(true);
        }
    }
    private MetroFrame frame;
    private String name;
    private ModCalItem ccItem;
    private ModelEditItem meItem;
}
